// pages/myaccount/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    account:null, //账号
    password:null ,//密码
    confirmpaw:null, //确认密码
    phone:null, //手机号
    prolist:null, 
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  
  onuserNameInput(e){
    let that = this;
    let account = e.detail.value;
    that.setData({
      account
    })
  },
  onpasWInput(e){
    let that = this;
    let password = e.detail.value;
    that.setData({
      password
    })
  },
  onconfirmPaw(e){
    let that = this;
    let confirmpaw = e.detail.value;
    console.log(e);
    that.setData({
      confirmpaw
    })
  },
  onphone(e){
    let that = this;
    let phone = e.detail.value;
    that.setData({
      phone
    })
  },
  /**立即注册**/
  onregistered(e){
    let that = this;
    let account = that.data.account;
    let password = that.data.password;
    let confirmpaw = that.data.confirmpaw;
    let phone = that.data.phone;
    // if(account==null && password==null && confirmpaw==null && phone==null){
    //   wx.showToast({  //弹框提示
    //     icon: 'none',
    //     title: '用户名不能为空！',
    //     duration: 2000,
    //   })
    // }
     if(account==null || account.length < 8){
      wx.showToast({icon: 'none', title: '用户名至少8位',duration: 1500 })
    }else if(password==null || password.length <8){
      wx.showToast({icon: 'none', title: '密码至少8位',duration: 1500 })
    }else if(confirmpaw==null || password!=confirmpaw){ 
      wx.showToast({ title: '确认密码出错', icon: 'loading', duration: 1500 }) 
    } else if (phone==null || !(/^1[34578]\d{9}$/.test(phone))) {
      wx.showToast({ title: '手机号填写错误', icon: 'loading', duration: 1500 }) 
    }else{
      wx.request({
        url: 'http://wxtp.hephp.cn/Index/reg',
        data:{
          uid:account,
          pass:password,
          phone:phone,
          getinfotype:1
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        method: "get",
        success(res){
          console.log(res.data);
          that.setData({
            prolist:res.data
          })
          let prolist = that.data.prolist;
          wx.showToast({ title: prolist.msg, icon: 'none', duration: 1500 }) 
          wx.navigateTo({
            url: '/pages/mypassword/mypassword',
          })
        }
      })
    }
    
    // else { 
    //   wx.showToast({ title: '注册成功', icon: 'success', duration: 2000 }) 
    // } 

    console.log(account);
    console.log(confirmpaw);
    console.log(phone);
  },

  /*返回*/
  navigateBack() {
    wx.navigateBack({
      delta: 1
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})